﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NTQOnlineExam.Services.Infrastructure.Encryption
{
    public interface IEncryptionService
    {
        /// <summary>
        /// Encrypts some text and return a string suitable for passing in a URL.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        string EncryptToString(string text);

        /// <summary>
        /// Encrypts some text and return an encrypted byte array.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        byte[] Encrypt(string text);


        /// <summary>
        /// Decryption when working with string
        /// </summary>
        /// <param name="encryptedString"></param>
        /// <returns></returns>
        string DecryptString(string encryptedString);

        /// <summary>
        /// Decryption when working with byte arrays
        /// </summary>
        /// <param name="encryptedValue"></param>
        /// <returns></returns>
        string Decrypt(byte[] encryptedValue);

        /// <summary>
        /// Generates checksum for specified data
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        string GenerateChecksum(string data);

        /// <summary>
        /// Verifies the checksum against specified data
        /// </summary>
        /// <param name="data"></param>
        /// <param name="checksum"></param>
        /// <returns></returns>
        bool VerifyChecksum(string data, string checksum);

        /// <summary>
        /// Generates a token from <c>data</c> string.
        /// The output token will include current timestamp which will be used to validate the token expiration.
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        string GenerateExpirableChecksum(string data);

        /// <summary>
        /// Verifies if the token is not expired and is matched to specific data.
        /// The expiration time is 30 minutes.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="checksum"></param>
        /// <returns></returns>
        bool VerifyExpirableChecksum(string data, string checksum);

        /// <summary>
        /// Verifies if the token is not expired and is matched to specific data.
        /// The expiration time is specified by <c>expirationMinutes</c>
        /// </summary>
        /// <param name="data"></param>
        /// <param name="checksum"></param>
        /// <param name="expiredTimeInMinute"></param>
        /// <returns></returns>
        bool VerifyExpirableChecksum(string data, string checksum, int expiredTimeInMinute);
    }

}
